function PFUtil() {"use strict";
}

PFUtil.findPath = function(fromX, fromY, toX, toY) {"use strict";
	var mapSizeX = Game.model.map.cells.length;
	var mapSizeY = Game.model.map.cells[0].length;
	//
	fromY = Math.floor(fromY);
	fromX = Math.floor(fromX);
	toY=Math.floor(toY);
	toX=Math.floor(toX);
	//
	if (toX<0 || toX>=mapSizeX || toY<0 || toY>=mapSizeY){
		return null;
	}
	// Find path
	var grid = new PF.Grid(mapSizeX, mapSizeY, Game.model.objectBag.busyCellsMap);
	var finder = new PF.AStarFinder({
		allowDiagonal: true,
		heuristic: PF.Heuristic.euclidean
	});
	var path = finder.findPath(fromY, fromX, toY, toX, grid);
	// Remove current position
	var newPath=[];
	var i, len;
	len = path.length;
	if (len>1){
		for (i=1;i<len;i++){
			newPath.push([path[i][1]+.5,path[i][0]+.5]);
		}
		return newPath;
	} else {
		return null;
	} 
};

PFUtil.drawPath = function(ctx, currX, currY, nextTaget, path) {"use strict";
	if (path) {
		var xx,yy;
		ctx.save();
		ctx.beginPath();
		xx = CoordinatesUtil.getX(currX, currY, 0, 0);
		yy = CoordinatesUtil.getY(currX, currY, 0, 0);
		ctx.moveTo(xx, yy);
		xx = CoordinatesUtil.getX(nextTaget[0], nextTaget[1], 0, 0);
		yy = CoordinatesUtil.getY(nextTaget[0], nextTaget[1], 0, 0);
		ctx.lineTo(xx, yy);
		var i;
		for (i=0;i<path.length;i++){
			xx = CoordinatesUtil.getX(path[i][0],path[i][1], 0, 0);
			yy = CoordinatesUtil.getY(path[i][0],path[i][1], 0, 0);
			ctx.lineTo(xx, yy);
		}
		ctx.strokeStyle = '#0000ff';
		ctx.lineCap = 'round';
		ctx.lineWidth = 2;
		ctx.stroke();
		ctx.restore();
	}
	//	
};
